version 16
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.X OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

/* PRELIMINARIES */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* DEFINE TREATMENT VARIABLE */

g				logtaxpaid=log(TaxPaid)
bys				regno:egen namefreq=min(name_count_v2)
qui				tab year, g(ydum)
g				after=year>=2012
g				female=(gender=="F" | gender=="f" | gender=="2")		
g				male=1-female

/* COMPLETE PANEL */

local			j=1
forvalues		n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap				drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui				xi: areg logtaxpaid i.year*i.male treat_after, absorb(regno) cluster(regno)
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* BALANCE PANEL */

bys				regno:g nreturns=_N
keep			if nreturns==10
local			j=2
forvalues		n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap				drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui				xi: areg logtaxpaid i.year*i.male treat_after, absorb(regno) cluster(regno)
local			i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

*--------------------------------
* PLACEBO REGRESSION 
*--------------------------------

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear

/* DEFINE TREATMENT VARIABLE */

g				logtaxpaid=log(TaxPaid)
bys				regno:egen namefreq=min(name_count_v2)
drop			if year>=2012
g				after=year>=2010
g				female=(gender=="F" | gender=="f" | gender=="2")		
g				male=1-female

/* COMPLETE PANEL */

local			j=1
forvalues		n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap				drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui				xi: areg logtaxpaid i.year*i.male treat_after, absorb(regno) cluster(regno)
local			i=4
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* BALANCE PANEL */

bys				regno:g nreturns=_N
keep			if nreturns==6
local			j=2
forvalues		n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap				drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui				xi: areg logtaxpaid i.year*i.male treat_after, absorb(regno) cluster(regno)
local			i=4
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* FORMATTING THE TABLE */ 

svmat 			table
keep			tab*
drop			table9-table12
keep			if _n<=6
g				c11=""
replace			c11="treat $\times$ after" in 1
replace			c11="Observations" in 3
replace			c11="treat $\times$ after" in 4
replace			c11="Observations" in 6

forvalues 		c=1/8 {
g				c`c'=string(table`c',"%9.3f")
}
foreach			r in 2 5 {
forvalues		c=1/8 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/8 {
replace			c`c'=string(table`c',"%15.0fc") in 3
replace			c`c'=string(table`c',"%15.0fc") in 6
}
forvalues		s=1/15 {
g				s`s'="&"
}
g				l="\\"
foreach			r in 2 3 5 6 {
replace			l="\\\\" in `r'
}
order			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 s12 l
browse			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 s12 l


